from socket import *
list = []

sock = socket()
sock.bind(("0.0.0.0",6888))
sock.listen(5)
#等待浏览器链接
while True:
    connfd,addr = sock.accept()
    print(f"Connect from {addr}")
    #接受HTTP请求
    data = connfd.recv(1024)
    if not data:
        break
    info = data.decode().split(" ")[1]
    try:
        file = open("."+info,"rb")
        data = file.read()
    except:
        continue
    response = "HTTP/1.1 200 OK\r\n"
    response += "Content-Type:image/jpeg\r\n"
    response += "\r\n"
    response = response.encode() + data
    # 发送响应
    connfd.send(response)

    connfd.close()

sock.close()